package com.woniuxy.repay.tools;

import java.util.ArrayList;
import java.util.List;

/**
 * @author shichen
 * @create 2021-11-21-21:39
 * @description
 */
public class ServiceTool {

    /**
     * 针对没有写分页查询的方法做的
     * @param list
     * @param pageIndex
     * @return
     */
    public static List createDataList(List list, Integer pageIndex) {
        ArrayList dataList = new ArrayList();
        int index = (pageIndex - 1) * 5;
        int size = list.size();
        if (index < size) {
            for (int i = 0; i < 5; i++) {

                if (index == size) {
                    break;
                }

                dataList.add(list.get(index));

                index++;
            }
        }
        return dataList;
    }

    public static Integer pageIndexTransition(Integer pageIndex){
        if (pageIndex < 1){
            throw new RuntimeException("pageIndex must greater than 0");
        }
        return (pageIndex-1)*5;
    }
}
